package com.qssoft.cqry.synchdb.properties;

import cn.hutool.core.util.ObjectUtil;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * redis db数据同步配置
 *
 * @author liju.z
 */
@Data
@ConfigurationProperties(prefix = "spring.synchdb")
public class SynchDbProperties {

    private RedisProperties redis;

    private SynchMysqlProperties masterDb;

    private SynchMysqlProperties slaveDb;

    @Value("${spring.application.name}")
    private String applicationName;


    @Data
    public static class SynchMysqlProperties {
        private String ip;
        private int port;
        private String username;
        private String password;
        private String serverId;
        private String tables;
        @Value("${spring.application.name}")
        private String applicationName;

        public String[] getTables() {
            if (ObjectUtil.isEmpty(tables)) return new String[]{};

            return tables.split(",");
        }

        public String getApplicationName(){
            return applicationName;
        }
    }
}
